home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / env_1_1 / part01
Encoding:
Internet Message Format  |  1990-07-08  |  7.4 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i202: env 1.1 - print out all environment variables, Part01/01
  5. Message-ID: <13080@xanth.cs.odu.edu>
  6. Date: 8 Jul 90 15:36:52 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: peterc@softway.sw.oz.au (Peter Chubb)
  9. Lines: 249
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: peterc@softway.sw.oz.au (Peter Chubb)
  15. Posting-number: Volume 90, Issue 202
  16. Archive-name: unix/env-1.1/part01
  17.  
  18. ENV is a utility to print out the values of all 1.3 Environment variables.
  19. It has been optimised for size, and takes less than 488 bytes.
  20. Moreover, unlike other routines I have seen for handling environment
  21. variables, it copes with variables with embedded newlines.
  22.  
  23. #!/bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 1)."
  30. # Contents:  Makefile env.c env.doc env.uu
  31. # Wrapped by tadguy@xanth on Sun Jul  8 11:36:44 1990
  32. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  33. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  34.   echo shar: Will not clobber existing file \"'Makefile'\"
  35. else
  36. echo shar: Extracting \"'Makefile'\" \(389 characters\)
  37. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  38. X#
  39. X# Makefile for env
  40. X#
  41. X# $Header: local:src/MINE/cmd/env/RCS/Makefile,v 1.2 90/05/26 12:55:30 peterc Exp $
  42. X# 
  43. X# $Log:    Makefile,v $
  44. X# Revision 1.2  90/05/26  12:55:30  peterc
  45. X# Added RCS goo
  46. X# 
  47. X#
  48. X#
  49. Xenv: env.o 
  50. X    blink from env.o to env nd
  51. X    protect env +p
  52. X
  53. Xenv.o: env.c
  54. X    lc -cus -v -O env.c
  55. X
  56. X
  57. Xinstall: env
  58. X    copy env local:bin
  59. X
  60. Xclean:
  61. X    rm -f env.o
  62. X
  63. Xclobber: clean
  64. X    rm -f env
  65. X
  66. X.DEFAULT:
  67. X    co $@
  68. END_OF_FILE
  69. if test 389 -ne `wc -c <'Makefile'`; then
  70.     echo shar: \"'Makefile'\" unpacked with wrong size!
  71. fi
  72. # end of 'Makefile'
  73. fi
  74. if test -f 'env.c' -a "${1}" != "-c" ; then 
  75.   echo shar: Will not clobber existing file \"'env.c'\"
  76. else
  77. echo shar: Extracting \"'env.c'\" \(1689 characters\)
  78. sed "s/^X//" >'env.c' <<'END_OF_FILE'
  79. X/************************************************************************
  80. X * env.c -- print all the environment                    *
  81. X *                                    *
  82. X *        Copyright 1990 Peter Chubb                *
  83. X *          All rights reserved                    *
  84. X *                                    *
  85. X ************************************************************************/
  86. X
  87. Xstatic char RCSID[] = "$Id: env.c,v 1.1 90/05/26 12:46:48 peterc Exp $";
  88. X
  89. X/*
  90. X *
  91. X * $Log:    env.c,v $
  92. X * Revision 1.1  90/05/26  12:46:48  peterc
  93. X * Initial revision
  94. X * 
  95. X *
  96. X */
  97. X
  98. X# include <exec/types.h>
  99. X# include <proto/dos.h>
  100. X# include <proto/exec.h>
  101. X# include <string.h>
  102. X
  103. X# define ENVDIR "ENV:"
  104. X# define BUFSIZ 512
  105. X
  106. Xvoid
  107. X_main()
  108. X{
  109. X    BPTR lck;
  110. X    BPTR Op;
  111. X    BPTR Ep;
  112. X    struct FileInfoBlock *FB = AllocMem(sizeof(struct FileInfoBlock), 0);
  113. X    long Status = 0;
  114. X    register char *p;
  115. X    register char *q;
  116. X    int          len;
  117. X    struct DosLibrary *DOSBase;
  118. X    char *buf = AllocMem(BUFSIZ, 0);
  119. X
  120. X    if (!(DOSBase = (struct DosLibrary *) OpenLibrary("dos.library", 0)))
  121. X        return;
  122. X
  123. X    Op  = Output();
  124. X  
  125. X    lck = Lock(ENVDIR, SHARED_LOCK);
  126. X    if (lck)
  127. X    {
  128. X        Status = Examine(lck, FB);
  129. X    if (Status)
  130. X        while (ExNext(lck, FB))
  131. X        {
  132. X        if (FB->fib_EntryType >= 0)
  133. X            continue;
  134. X        Write(Op, FB->fib_FileName, strlen(FB->fib_FileName));
  135. X        Write(Op, "=", 1);
  136. X        for (p = ENVDIR, q = buf; *p; *q++ = *p++)
  137. X            ;
  138. X        for (p = FB->fib_FileName; *p; *q++ = *p++)
  139. X            ;
  140. X        *q = '\0';
  141. X
  142. X    if ((Ep = Open(buf, MODE_OLDFILE)) != (BPTR)0)
  143. X        {
  144. X            if ((len = Read(Ep, buf, BUFSIZ)) > 0)
  145. X            {
  146. X                Write(Op, buf, len);
  147. X            }
  148. X            Close(Ep);
  149. X        }
  150. X        Write(Op, "\n", 1);
  151. X        }
  152. X    UnLock(lck);
  153. X    }
  154. X
  155. X    CloseLibrary((struct Library *)DOSBase);
  156. X    FreeMem(buf, BUFSIZ);
  157. X    FreeMem(FB, sizeof (*FB));
  158. X}
  159. END_OF_FILE
  160. if test 1689 -ne `wc -c <'env.c'`; then
  161.     echo shar: \"'env.c'\" unpacked with wrong size!
  162. fi
  163. # end of 'env.c'
  164. fi
  165. if test -f 'env.doc' -a "${1}" != "-c" ; then 
  166.   echo shar: Will not clobber existing file \"'env.doc'\"
  167. else
  168. echo shar: Extracting \"'env.doc'\" \(1311 characters\)
  169. sed "s/^X//" >'env.doc' <<'END_OF_FILE'
  170. X    ENV -- print out environment variables.
  171. X
  172. X    ENV is a 484 byte program that prints out the values of all the
  173. X    1.3 Environment variables.  It is fully reentrant (i.e.,
  174. X    can be made resident).
  175. X
  176. XTo use, just type
  177. X    env
  178. X
  179. X    The result is a list of environment variables in the form
  180. X    NAME=Value, one per line.
  181. X
  182. XBUGS:
  183. X    Environment variables whose values are greater than 511 bytes
  184. X    long are truncated at 511 bytes.
  185. X
  186. XAUTHOR:
  187. X    Peter Chubb    (peterc@softway.oz.au)
  188. X
  189. X
  190. X    Copyright 1990 Peter Chubb
  191. X    All rights reserved.
  192. X    This program and its associated documentation may not be
  193. X    distributed for profit.  It may be distributed provided
  194. X    a) no charge is made other than for reasonable copying and
  195. X       media expenses, 
  196. X    b) no change is made to the source, documentation or binary, 
  197. X       that is not clearly marked as being a change, and
  198. X    c) all files are provided.  These comprise:
  199. X        env.doc -- this documentation file
  200. X        env     -- the program binary
  201. X        Makefile-- to make the program
  202. X        env.c    -- the program source.
  203. X
  204. X    This program is not warranted, or guaranteed.
  205. X    You get exactly what you paid for -- a copy of the program to
  206. X    do as you wish with.  If it crashes your machine, writes rude
  207. X    letters to your spouse, or explodes in your face ... caveat
  208. X    emptor!  However, to the best of my knowledge and belief it
  209. X    works as advertised. 
  210. END_OF_FILE
  211. if test 1311 -ne `wc -c <'env.doc'`; then
  212.     echo shar: \"'env.doc'\" unpacked with wrong size!
  213. fi
  214. # end of 'env.doc'
  215. fi
  216. if test -f 'env.uu' -a "${1}" != "-c" ; then 
  217.   echo shar: Will not clobber existing file \"'env.uu'\"
  218. else
  219. echo shar: Extracting \"'env.uu'\" \(711 characters\)
  220. sed "s/^X//" >'env.uu' <<'END_OF_FILE'
  221. Xbegin 500 env
  222. XM```#\P`````````"``````````$```!@````#````^D```!@3E7_\$CG-S`@Y
  223. XM/````01R`"QX``1.KO\Z)$`@2B](`"@@/````@!R`$ZN_SHO0``D0_H!.'``[
  224. XM3J[]V"9`($LO2``@(`MG``$<)&\`*"9(+$M.KO_$+@!#^@$>(@ET_DZN_ZPL!
  225. XM`$J&9P``UB(&)`I.KO^:2H!G``#`8```K"`J`'A*@&H``*(D;P`H)F\`($'JH
  226. XM``@B2$H99OQ3B9/(+T@`'"(')`@F"2Q+3J[_T"('0_H`S"0)=@%.KO_01_H`I
  227. XMNB1O`"1@`A3;2A-F^B9O`!Q@`A3;2A-F^D(2)F\`("1O`"0B"BQ+)#P```/MQ
  228. XM3J[_XBH`2H5G("(%)`HF/````@!.KO_62H!O""(')@!.KO_0(@5.KO_<(@=!J
  229. XM^@!F)`AV`4ZN_]`D;P`H(@8D"BQ+3J[_E$J`9@#_2"(&+$M.KO^F(DLL>``$Q
  230. XM3J[^8B)O`"0@/````@!.KO\N(DH@/````01.KO\N3-\,[$Y=3G5D;W,N;&EB*
  231. XM<F%R>0!%3E8Z```]``H````#\@```^H````,)$ED.B!E;G8N8RQV(#$N,2`Y&
  232. XB,"\P-2\R-B`Q,CHT-CHT."!P971E<F,@17AP("0````#\G8NU
  233. X``
  234. Xend
  235. Xsize 484
  236. END_OF_FILE
  237. if test 711 -ne `wc -c <'env.uu'`; then
  238.     echo shar: \"'env.uu'\" unpacked with wrong size!
  239. fi
  240. # end of 'env.uu'
  241. fi
  242. echo shar: End of archive 1 \(of 1\).
  243. cp /dev/null ark1isdone
  244. MISSING=""
  245. for I in 1 ; do
  246.     if test ! -f ark${I}isdone ; then
  247.     MISSING="${MISSING} ${I}"
  248.     fi
  249. done
  250. if test "${MISSING}" = "" ; then
  251.     echo You have the archive.
  252.     rm -f ark[1-9]isdone
  253. else
  254.     echo You still need to unpack the following archives:
  255.     echo "        " ${MISSING}
  256. fi
  257. ##  End of shell archive.
  258. exit 0
  259. -- 
  260. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  261. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  262. Post requests for sources, and general discussion to comp.sys.amiga.
  263.